package pers.cz.common.connect.simpledb;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pers.cz.common.connect.Connection;
import pers.cz.common.exception.ExceptionUtil;

import javax.sql.DataSource;
import java.sql.SQLException;

/**
 * @program: JefLogTail
 * @description: 数据库连接，
 * @author: Cheng Zhi
 * @create: 2023-03-05 13:35
 **/
public class DbConnnection extends Connection {

    Logger logger = LoggerFactory.getLogger(DbConnnection.class);

    java.sql.Connection connection;

    public DbConnnection(DataSource dataSource) {
        try {
            // 由于使用的是druid管理数据库连接，所以这里不需要做单例
            connection = dataSource.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
            ExceptionUtil.rethrow(e);
        }
    }

    @Override
    public void close() {
        try {
            connection.close();
        } catch (SQLException e) {
            ExceptionUtil.rethrow(e);
        }
    }

    @Override
    public Object getConnectin() {
        return this.connection;
    }

}
